﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class ServiceTypeTicketCategoryBus
    {
        private ServiceTypeTicketCategoryDao dao;
        public ServiceTypeTicketCategoryBus()
        {
            dao = new ServiceTypeTicketCategoryDao();
        }

        public bool insert(ServiceTypeTicketCategory serviceTypeTicketCategory) {
            return dao.insert(serviceTypeTicketCategory);
        }

        public bool update(ServiceTypeTicketCategory serviceTypeTicketCategory) {
            return dao.update(serviceTypeTicketCategory);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public ServiceTypeTicketCategory get(int id) {
            DataTable dt = dao.get(id);
            ServiceTypeTicketCategory serviceTypeTicketCategory = new ServiceTypeTicketCategory();

            if (dt.Rows.Count > 0)
            {
                serviceTypeTicketCategory.Id = Convert.ToInt32(dt.Rows[0]["STC_ID"]);
                serviceTypeTicketCategory.ServiceTypeId = Convert.ToInt32(dt.Rows[0]["SVT_ID"]);
                serviceTypeTicketCategory.TicketCategoryId = Convert.ToInt32(dt.Rows[0]["TKC_ID"]);
            }
            return serviceTypeTicketCategory;
        }

        public List<ServiceTypeTicketCategory> getAll() {
            DataTable dt = dao.getAll();
            List<ServiceTypeTicketCategory> list = new List<ServiceTypeTicketCategory>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    ServiceTypeTicketCategory serviceTypeTicketCategory = new ServiceTypeTicketCategory();
                    serviceTypeTicketCategory.Id = Convert.ToInt32(dr["STC_ID"]);
                    serviceTypeTicketCategory.ServiceTypeId = Convert.ToInt32(dr["SVT_ID"]);
                    serviceTypeTicketCategory.TicketCategoryId = Convert.ToInt32(dr["TKC_ID"]);

                    list.Add(serviceTypeTicketCategory);
                }

            }
            return list;
        }
    }
}
